<?php


namespace app\api\controller;
use app\api\model\Music as MusicModel;

class Music extends Controller
{
    public function index($musicid,$uid,$type){
        $model=new MusicModel();
        $music=$model->where(['uid'=>$uid,'musicid'=>$musicid,'type'=>$type])->select();
        if(!empty($music)){
            return $this->renderSuccess(['fav'=>true],'已存在喜欢');}
        else{return $this->renderSuccess(['fav'=>false],'不存在喜欢');}
    }
    public function addLike($musicid,$uid,$type)
    {
        $model = new MusicModel();
        $music = $model->where(['uid' => $uid, 'musicid' => $musicid,'type'=>$type])->select();
        if (empty($music)) {
            $model->save($this->request->param());
            return $this->renderSuccess(['fav' => true], '添加成功');
        } else {
            $model->where(['uid' => $uid, 'musicid' => $musicid,'type'=>$type])->delete();
            return $this->renderSuccess(['fav' => false],'已存在');

        }
    }
public function getLikeSongsByUser($uid){
        $model=new MusicModel();
        $songsList=$model->where(['uid'=>$uid,'type'=>2])->select();
        return $this->renderSuccess($songsList, '查找成功');

}
    public function getLikeListByUser($uid){
        $model=new MusicModel();
        $songsList=$model->where(['uid'=>$uid,'type'=>1])->select();
        return $this->renderSuccess($songsList, '查找成功');

    }
    public function getSongsLike(){
        $model=new MusicModel();
        $userList=$model->select();
        return $this->renderSuccess($userList,'获取列表成功');
    }
}
